package com.appdemo.demo.config;

import com.appdemo.demo.rulelistener.MyRuleEngineListener;
import com.appdemo.demo.rulelistener.MyRulesListener;
import com.appdemo.demo.init.ProtoRulesEngineFactoryBean;
import org.jeasy.rules.api.RulesEngine;
import org.jeasy.rules.core.DefaultRulesEngine;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;

public class RuleEngineConfig {


    @Bean(name = "myEngine")
    @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public RulesEngine myEngine(MyRulesListener myRulesListener, MyRuleEngineListener myRuleEngineListener) {
        DefaultRulesEngine rulesEngine = new DefaultRulesEngine();
        rulesEngine.registerRuleListener(myRulesListener);
        rulesEngine.registerRulesEngineListener(myRuleEngineListener);
        return rulesEngine;
    }
    @Bean("myEngine2")
    ProtoRulesEngineFactoryBean rulesEngineFactoryBean()
    {
        return new ProtoRulesEngineFactoryBean();
    }
}
